Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

213
Visualizações
Is there a "use default parameter" argument syntax for functions?

If I have a function declared with two default parameters, like this:

const doSomething = (defaultVal = 'me default', useThis = false) => {
      /* ... */
};

And I want to call the function passing in an argument for the second parameter, but have the first argument just use the default value:

doSomething(???, true);

Is there some syntax for telling the function to use the default parameter, or does a real value need to be passed in?

about 4 years ago · Santiago Gelvez
2 Respostas
Responde à pergunta

0

Pass in undefined

const doSomething = (defaultVal = 'me default', useThis = false) => {
  console.log({ defaultVal, useThis });
};

doSomething(undefined, true)

about 4 years ago · Santiago Gelvez Relatório

0

There is no syntax or key for that purpose. You should use default parameters as last. For that example if useThis parameter will be given a value for everytime you can give useThis as first argument.

Alternatively you can give an object as parameter. Inside the function you can merge your template (default valued object) and argument object then use it in you function.

const fn = (props) => {

    const newProps = {
        defaultVal : "default",
        useThis : false,
        ...props
    }

}
about 4 years ago · Santiago Gelvez Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda